
#ifndef _UART_H_
#define _UART_H_

#include "stm32f4xx.h"
#include "stdio.h"
/*=====================================================================================================*/
/*                      USART                                                                          */
/*=====================================================================================================*/
#define USARTx1                USART1
#define USART1_CLK            RCC_APB2Periph_USART1

#define USART1_TX_PIN         GPIO_Pin_9
#define USART1_TX_GPIO_PORT   GPIOA
#define USART1_TX_GPIO_CLK    RCC_AHB1Periph_GPIOA
#define USART1_TX_SOURCE      GPIO_PinSource9
#define USART1_TX_AF          GPIO_AF_USART1

#define USART1_RX_PIN         GPIO_Pin_10
#define USART1_RX_GPIO_PORT   GPIOA
#define USART1_RX_GPIO_CLK    RCC_AHB1Periph_GPIOA
#define USART1_RX_SOURCE      GPIO_PinSource10
#define USART1_RX_AF          GPIO_AF_USART1

#define USART1_BAUDRATE       57600
#define USART1_BYTESIZE       USART_WordLength_8b
#define USART1_STOPBITS       USART_StopBits_1
#define USART1_PARITY         USART_Parity_No
#define USART1_Mode           (USART_Mode_Rx | USART_Mode_Tx)
#define USART1_HARDWARECTRL   USART_HardwareFlowControl_None

#define USARTx3                USART3
#define USART3_CLK            RCC_APB1Periph_USART3

#define USART3_TX_PIN         GPIO_Pin_8
#define USART3_TX_GPIO_PORT   GPIOD
#define USART3_TX_GPIO_CLK    RCC_AHB1Periph_GPIOD
#define USART3_TX_SOURCE      GPIO_PinSource8
#define USART3_TX_AF          GPIO_AF_USART3

#define USART3_RX_PIN         GPIO_Pin_9
#define USART3_RX_GPIO_PORT   GPIOD
#define USART3_RX_GPIO_CLK    RCC_AHB1Periph_GPIOD
#define USART3_RX_SOURCE      GPIO_PinSource9
#define USART3_RX_AF          GPIO_AF_USART3

#define USART3_BAUDRATE       115200
#define USART3_BYTESIZE       USART_WordLength_8b
#define USART3_STOPBITS       USART_StopBits_1
#define USART3_PARITY         USART_Parity_No
#define USART3_Mode           (USART_Mode_Rx | USART_Mode_Tx)
#define USART3_HARDWARECTRL   USART_HardwareFlowControl_None

#define USARTx4               UART4
#define USART4_CLK            RCC_APB1Periph_UART4

#define USART4_TX_PIN         GPIO_Pin_0
#define USART4_TX_GPIO_PORT   GPIOA
#define USART4_TX_GPIO_CLK    RCC_AHB1Periph_GPIOA
#define USART4_TX_SOURCE      GPIO_PinSource0
#define USART4_TX_AF          GPIO_AF_UART4

#define USART4_RX_PIN         GPIO_Pin_1
#define USART4_RX_GPIO_PORT   GPIOA
#define USART4_RX_GPIO_CLK    RCC_AHB1Periph_GPIOA
#define USART4_RX_SOURCE      GPIO_PinSource1
#define USART4_RX_AF          GPIO_AF_UART4

#define USART4_BAUDRATE       115200
#define USART4_BYTESIZE       USART_WordLength_8b
#define USART4_STOPBITS       USART_StopBits_1
#define USART4_PARITY         USART_Parity_No
#define USART4_Mode           (USART_Mode_Rx | USART_Mode_Tx)
#define USART4_HARDWARECTRL   USART_HardwareFlowControl_None

#define USARTx6                USART6
#define USART6_CLK            RCC_APB2Periph_USART6

#define USART6_TX_PIN         GPIO_Pin_6
#define USART6_TX_GPIO_PORT   GPIOC
#define USART6_TX_GPIO_CLK    RCC_AHB1Periph_GPIOC
#define USART6_TX_SOURCE      GPIO_PinSource6
#define USART6_TX_AF          GPIO_AF_USART6

#define USART6_RX_PIN         GPIO_Pin_7
#define USART6_RX_GPIO_PORT   GPIOC
#define USART6_RX_GPIO_CLK    RCC_AHB1Periph_GPIOC
#define USART6_RX_SOURCE      GPIO_PinSource7
#define USART6_RX_AF          GPIO_AF_USART6

#define USART6_BAUDRATE       115200
#define USART6_BYTESIZE       USART_WordLength_8b
#define USART6_STOPBITS       USART_StopBits_1
#define USART6_PARITY         USART_Parity_No
#define USART6_Mode           (USART_Mode_Rx | USART_Mode_Tx)
#define USART6_HARDWARECTRL   USART_HardwareFlowControl_None

/*=====================================================================================================*/
/*=====================================================================================================*/
uint8_t usart1_tx_ringbuffer_push(const uint8_t* ch, uint8_t len);
int usart1_char_available(void);
uint8_t usart1_rx_ringbuffer_pop(void);
uint8_t usart1_rx_ringbuffer_push_from_usart(void);
uint8_t usart1_tx_ringbuffer_pop_to_usart(void);
void UART1Config(void);
void UART1NVIC_Configuration(void);
void UART3Config(void);
void UART3NVIC_Configuration(void);
void UART4Config(void);
void UART4NVIC_Configuration(void);
void UART6Config(void);
int fputc(int ch, FILE *f);

#endif

